<template>
<div class="PageNewpolicyEdit">
    <router-view :key="$route.path"></router-view>
    <div class="form-area">
        <el-form ref="form" :model="form" label-width="100px" v-loading="listLoading">

            <el-form-item label="政策标题">
                <el-input v-model="form.title"></el-input>
            </el-form-item>

            <el-form-item label="发布日期">
                <el-date-picker v-model="form.publishDate" type="date" placeholder="选择日期"></el-date-picker>
            </el-form-item>

            <el-form-item label="全文">
                <!--<el-input type="textarea" v-model="form.content" :rows="8"></el-input>-->
                <tinymce v-model="form.content" :height="300" menubar="" :toolbar="tinymce_toolbar"/>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="onSubmit">提交</el-button>
            </el-form-item>

        </el-form>
    </div>

</div>
</template>

<script>

import {getNewpolicyById, tableDataList, deletePolicy, updNewpolicy} from '@/api/policy-collect-data';
import Tinymce from '@/components/Tinymce'


export default {
    name: 'PageNewpolicyEdit',
    components: { Tinymce },
    data() {
        return {
            tinymce_toolbar : ['bold | alignleft aligncenter alignright | code'],

            policyId: '',
            listLoading: false,

            form: {
              id: '',
              title: '',
              publishDate: '',
              content: '',

              /*url: '',
              category: '',
              endDate: '',
              level: '',
              validity: '',
              keyword: [],
              number: '',
              fileUrl: '',*/
            },
        }
    },
    computed: { },
    mounted(){
        console.log('[mounted]');
    },
    created() {
        console.log('[created]');
        if (this.$route.query.id) {
            this.policyId = this.$route.query.id;
            this.getPolicy();
        }
    },
    methods: {
 
            // { "id": 5, "publishDate": "2020-09-07","title": "修改后的标题", "content": "带标签的内容", "contentText": "不带标签的内容" }
        onSubmit() {
            console.log('[onSubmit]', this.form);
            this.listLoading = true;
            updNewpolicy(this.form).then(res => {
                this.listLoading = false;
                this.$message({ message: "修改成功", type: "success" });
            });
        },
        getPolicy() {
            if (this.policyId) {
                this.listLoading = true;
                getNewpolicyById({id: this.policyId}).then(res => {
                    this.listLoading = false;
                    for(let key in this.form){
                        //console.log(key, this.form[key]);
                        this.form[key] = res.result[key] || '';
                    }
                    //this.form = res.result;
                });
            }
        },
    }
}
</script>
<style lang="less" scoped>
.PageNewpolicyEdit {
    padding-top: 24px;

    .form-area {
        width: 70%;
        margin: auto;

        .el-input, .el-date-picker, .el-select {
            width: 400px;
        }
    }


}
</style>
<style lang="less">
.tinymce-container .editor-custom-btn-container{
    display:none!important;
}
</style>
